package service;

import mapper.FuncModuleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import po.FuncModule;
import po.FuncModuleCustom;
import po.Result;

import java.util.List;

@Service
public class FuncModuleServiceImpl implements FuncModuleService {

    @Autowired
    private FuncModuleMapper funcModuleMapper;

    @Override
    public List<FuncModuleCustom> findAllFuncModuleCustom(String appName) throws Exception {
        return funcModuleMapper.findAllFuncModuleCustom(appName);
    }

    @Override
    public Result addFuncModule(FuncModule funcModule) {
        Result result = new Result();
        try {
            funcModuleMapper.addFuncModule(funcModule);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("添加失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("添加成功！");
        return result;
    }

    @Override
    public Result deleteFuncModule(int id) {
        Result result = new Result();
        try {
            funcModuleMapper.deleteFuncModuleById(id);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("删除失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("删除成功！");
        return result;
    }

    @Override
    public List<FuncModule> findModuleByAppId(int app_id) throws Exception {
        return funcModuleMapper.findModuleByAppId(app_id);
    }

    @Override
    public Result updateFuncModuleById(int id, FuncModule funcModule) {
        Result result = new Result();
        try {
            funcModule.setId(id);
            funcModuleMapper.updateFuncModuleById(funcModule);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("修改失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("修改成功！");
        return result;
    }
}
